package com.aidong.service;

/**
 * Created by john on 16-11-2.
 */
import com.aidong.cache.ItemCache;
import com.aidong.common.JobConsts;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

@Service
public class BaseJobService {
    protected Logger log = Logger.getLogger(BaseJobService.class);
    @Resource
    protected ItemCache cache;

    public BaseJobService() {
    }

    protected String getTemplatePath() {
        return this.cache.getValue("setting", JobConsts.EXCEL_TEMPLATE_PATH_KEY);
    }

    protected String getDownloadPath() {
        return this.cache.getValue("setting", JobConsts.EXCEL_OUT_PATH_KEY);
    }

    protected Date parseDate(String str, String format) {
        return this.parseDate(str, new SimpleDateFormat(format));
    }

    protected Date parseDate(String str, SimpleDateFormat sdf) {
        if(str != null && str.length() > 0) {
            try {
                return sdf.parse(str);
            } catch (Exception var4) {
                ;
            }
        }

        return null;
    }

    protected Date getTrimDate(Date dt) {
        if(dt == null) {
            return null;
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            return this.parseDate(sdf.format(dt), sdf);
        }
    }

    protected Date getYesterday() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return this.parseDate(sdf.format(new Date(System.currentTimeMillis() - 3600000L & 24L)), sdf);
    }
}